<?php

include_once '../inc/db_util.php';

function find($filter) {
    $array_wiki = array();
    $jsArray = json_decode($filter, false);
    $query = mysql_query("SELECT * FROM tb_log tl 
				JOIN tb_wiki tw ON tl.id_wiki=tw.id_wiki
				LEFT JOIN tb_dosen td on tl.id_user=td.nip
                LEFT JOIN tb_mahasiswa tm on tl.id_user=tm.id_mahasiswa
				WHERE tw.id_wiki='" . $jsArray->{'Id'} . "'
				ORDER BY tanggal_edit DESC");
        
    while ($row = mysql_fetch_array($query, MYSQL_BOTH)) {
        $row_array['Id'] = $row['id_wiki'];
        $row_array['Judul'] = $row['judul'];
        $row_array['Isi'] = $row['isi_lama'];
        $row_array['Created'] = $row['tanggal_edit'];
        $row_array['Creator']['IdUser'] = $row['id_user'];
        $row_array['Creator']['Nama'] = $row['nama'] == '' ? $row['namadosen'] : $row['nama'];
        $row_array['Creator']['Type'] = $row['nama'] == '' ? 'Dosen' : 'Mahasiswa';

        array_push($array_wiki, $row_array);
    }
    return json_encode($array_wiki);
}

?>
